<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>材料调转</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../resources/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../resources/css/style.css" media="all">
    <style>
        .layui-form-label{width: 100px; height: 20px;}
        .layui-form-select{width: 190px;}
        #gonghuoshijian{ width: 100%;}
        .addUser input{width: 86%;}
        .layui-form-select{width: 90%!important;}
        .layui-form-select input{width: 100%;}
        .layui-form-item{padding-left: 0;}
        .layui-form-item .layui-input-inline{width: 73%!important;}
        .masksx{width: 800px;}
        .material{display: flex;justify-content: flex-start;padding-left: 15px;padding-right: 77px;margin-bottom: 8px;width: 100%;margin-left: 55px;}
        .material label{float: left;height: 38px;line-height: 38px; display: inline-block;}
        ._mater{width: 49%;margin-left: 30px;}
        .layui-form-select .layui-input{padding-right: 0;}
        ._materwarp{width: 43%;}
        .masksx .forms{padding: 0;}
        .material ._mater_input{width: 10%;}
        ._mater_lab{margin:0 20px;}
        .addTo{background-color: #86B1FC;color: #FFF; width: 10px;height: 10px;display: none}
        .materialone .addTo{display:inline;}
        .mater_btn{margin: 6px 0 0 6px;}
        .material_C{width: 100px;text-align: justify;}
        .material_C:after{content:'';width: 100%;display: inline-block;}
        .materialone .mater_btn{display: none;}
        .layui-form-selectup dl{top: -184px;}
        @media screen and (max-width: 750px){
            .MOVE_queryon .layui-form-item {
                width: 80%;
            }
            .layui-form-item{padding: 0;}
            .MOVE_footer{text-align: right;}
            .MOVE_footer a{color: #FFF;font-size: 20px;line-height: 30px;
                padding: 10px;background-color: #F5A721;height: 100%;position: absolute;right: 0;}
        }
        .layui-form-pane .layui-input-inline{width: 80%;}
        .titles{text-align: center;margin: 0;font-size: 20px;}
        .xuanzhong .layui-input-block{margin-left: 0;}
        .beixuan table th{width: 33.333%;}
        .masksx{height: 80%;width: 80%;}
        .layui-table tbody th {text-align: center;}
        .beixuan tr th{width: auto!important;}
        .mask input{width: 100%!important; padding: 0;margin: 0;}
        .mask .xuanzhong,.beixuan{height: 220px;overflow: auto;}
        .layui-input-block{margin-left: 200px;}
        .layui-table td, .layui-table th{padding: 0;}
        .tijiao{width: 150px;}
        .xiangmunanmes{font-size: 16px;text-align: left;margin: 20px 0;overflow:hidden;margin: 0 5px;}
        .xiangmunanmes li{width:50%;float: left;margin-top: 5px;}
        .xiangmunanmes li:before{content:'';}
        .mingchengs{width: 30%;display: inline-block;float: left;font-weight: bolder;}
        .mingR{width: 70%;display: inline-block;}
        .xuanzhong,.beixuan{margin: 0 5px;}
        .xuanzhong td{text-align: center;}
        .topS th,.topS td{height: 40px;line-height: 40px;text-align: center;}
        .xuanzhong th,.xuanzhong td{height: 40px;line-height: 40px;text-align: center;}
    </style>
</head>
<body>
<div class="_PC">
    <form class="layui-form layui-form-pane" id="form_7grid" action="" lay-filter="hetong">
        <div class="formTop layui-row">
            <div class="layui-inline layui-col-lg2 layui-col-md2 layui-col-xs2">
                <div class="layui-input-inline" style="width: 80%;">
                    <input type="text" name="username" lay-verify="required" placeholder="请输入项目名称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline layui-col-lg2 layui-col-md2 layui-col-xs2">
                <div class="layui-input-inline" style="width: 80%;">
                    <input type="text" name="jsr" lay-verify="required" placeholder="请输入创建人" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline layui-col-lg2 layui-col-md2 layui-col-xs2">
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="test-limit3" placeholder="请输入供料开始日期">
                    <div class="icons">

                    </div>
                </div>
            </div>
            <div class="layui-inline layui-col-lg2 layui-col-md2 layui-col-xs2">
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="test-limit4" placeholder="请输入供料结束日期">
                    <div class="icons">
                    </div>
                </div>
            </div>
            <div class="layui-inline layui-col-lg3 layui-col-md3 layui-col-xs3">
                <button class="layui-btn chaxun" type="button"  onclick="query()">查询</button>
                <button class="layui-btn layui-btn-danger quanxian" type="button" QX="api/material/matSend.do" onclick="diaozhuan()">材料调转</button>
            </div>
        </div>
        <table id="demo" lay-filter="test"></table>
        <script type="text/html" id="barDemo">
            <a class="layui-btn layui-btn-sm layui-btn-normal fahuo quanxian" lay-event="xiangqing" QX="api/supply/builFeedManagerVali.do">详情</a>
            <!--<a class="layui-btn layui-btn-danger layui-btn-sm chakan" lay-event="look">查看</a>-->
            <!--<a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="edit">编辑</a>-->
        </script>
        <!--<script type="text/html" id="titleTpl">-->
        <!--<span>{{times(1510635999999)}}</span>-->
        <!--</script>-->
    </form>
    <div id="demo7"></div>
    <a class="dayin" type="button" id="dlink" onclick="" style="float: right; position: fixed; right: 50px; bottom: 50px; z-index: 999;"></a>
    <div class="mask">
        <div class="masksx">
            <div class="title"><span class="titleL">材料调转</span><span class="close">×</span></div>
            <div class="forms">
                <form class="layui-form addUser" method="post" action="">
                    <div class="titles">材料调转(调出方)</div>
                    <div class="layui-form-item" lay-filter="suoshuqiye">
                        <label class="layui-form-label">选择调出合同<span class="maohao">：</span></label>
                        <div class="layui-input-block">
                            <div class="layui-form" >
                                <select lay-verify="required" lay-filter="test" name="diaochu" lay-search="" class="compid"  >
                                    <option value=""></option>
                                    <!--<option value="2">2</option>-->
                                </select>

                            </div>
                        </div>
                    </div>
                    <div class="xuanzhong">
                        <table class="layui-table">
                            <thead>
                            <tr>
                                <th>
                                </th>
                                <th>材料名</th>
                                <th>规格</th>
                                <th>签收数量</th>
                                <th>审核数量</th>
                                <th>计量单位</th>
                            </tr>
                            </thead>
                            <tbody>
                            <!--<tr>-->
                            <!--<th>-->
                            <!--<div class="layui-form-item" pane="">-->
                            <!--<div class="layui-input-block">-->
                            <!--<input type="checkbox" name="like1[write]" lay-filter="filter" lay-skin="primary" title='' checked="">-->
                            <!--</div>-->
                            <!--</div>-->
                            <!--</th>-->
                            <!--<th>铸铁井盖</th>-->
                            <!--<th>100*200</th>-->
                            <!--<th>3</th>-->
                            </tr>
                            </tbody>
                        </table>
                    </div>
                    <div class="beixuan">
                        <div class="titles">材料调转(接收方)</div>
                        <div class="layui-form-item" lay-filter="suoshuqiye">
                            <label class="layui-form-label">选择接收合同<span class="maohao">：</span></label>
                            <div class="layui-input-block">
                                <div class="layui-form">
                                    <select lay-verify="required" name="jieshou" lay-search="" lay-filter="test3" class="compid"  >
                                        <option value=""></option>
                                       <!--<option value="2">2</option>-->
                                    </select>
                                </div>
                            </div>
                        </div>
                        <table class="layui-table">
                            <thead>
                            <tr>
                                <th>材料名</th>
                                <th>规格</th>
                                <th>审核数量</th>
                                <th>签收数量</th>
                                <th>转料数量</th>
                                <th>计量单位</th>
                            </tr>
                            </thead>
                            <tbody>
                            <!--<tr>-->
                            <!--<th>铸铁井盖</th>-->
                            <!--<th>100*200</th>-->
                            <!--<th>-->
                            <!--<input type="number" class="inputs" lay-verify="required"/>-->
                            <!--</th>-->
                            <!--</tr>-->
                            </tbody>
                        </table>
                    </div>
                    <div class="_submit" style="text-align: right;">
                        <button class="layui-btn layui-btn-sm layui-btn-disabled tijiao" lay-submit lay-filter="_subm" style="margin-right: 50px;">调转</button>
                    </div>

                </form>

            </div>

        </div>

    </div>
    <div class="masktow">
        <div class="masksx">
            <div class="title"><span class="titleL">材料调转详情</span><span class="close">×</span></div>
            <div class="forms">
                <form class="layui-form addUser" method="post" action="">
                    <div class="titles">转出记录</div>
                    <!--<ul class="xiangmunanmes">-->
                        <!--<li><span class="mingchengs">材料转出合同方:</span> <span class="diaochu mingR"></span></li>-->
                        <!--<li><span class="mingchengs">材料接收合同方:</span> <span class="jieshou mingR"></span></li>-->
                        <!--<li><span class="mingchengs">材料调转时间:</span> <span class="times mingR"></span></li>-->
                        <!--<li><span class="mingchengs">材料调转操作人:</span> <span class="operator mingR"></span></li>-->

                    <!--</ul>-->
                    <table class="layui-table topS">
                        <thead>
                            <tr>
                                <th>材料转出合同方</th>
                                <th>材料接收合同方</th>
                                <th>材料调转时间</th>
                                <th>材料调转操作人</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td class="diaochu"></td>
                                <td class="jieshou"></td>
                                <td class="times"></td>
                                <td class="operator"></td>
                            </tr>
                        </tbody>
                    </table>
                    <div class="xuanzhong">
                        <table class="layui-table">
                            <thead>
                            <tr>
                                <th>材料名</th>
                                <th>规格</th>
                                <th>计量单位</th>
                                <th>转出数量</th>
                                <th>签收数量</th>
                                <th>审核数量</th>
                            </tr>
                            </thead>
                            <tbody>
                                <!--<tr>-->
                                    <!--<td></td>-->
                                    <!--<td></td>-->
                                    <!--<td></td>-->
                                    <!--<td></td>-->
                                    <!--<td></td>-->
                                <!--</tr>-->
                            </tbody>
                        </table>
                    </div>

                </form>

            </div>

        </div>

    </div>

</div>



<script src="../../../resources/layui/layui.js" charset="utf-8"></script>
<script src="../../../resources/js/style.js"></script>
<script src="../../../resources/js/api.js"></script>
<script>
    function diaozhuan() {
        $('.mask').show();
        $('[name="diaochu"]').val('');
        $('[name="jieshou"]').val('');
        $('.xuanzhong tbody').html('');
        $('.beixuan tbody').html('');
        layui.use(['form', 'layedit', 'laydate','table','element'], function() {
            var form=layui.form;
            form.render();
        })
    }
    function query() {
        layui.use(['form', 'layedit', 'laydate','table','element'], function() {
            var form = layui.form
                , table = layui.table;
            var pronName=$("[name='username']").val();
            var jsr=$('[name="jsr"]').val();
            var bengintime=$('#test-limit3').val();
            var endtime=$('#test-limit4').val();


            if(!AntiSqlValid(pronName)){
                if(lbq('api/matperson/loadGysFeedSel.do')){
                    API.cailiaodiaozhuan({'type':'a','proName':pronName,'jsr':jsr,'bengintime':bengintime,'endtime':endtime,'p':getCookie('yanzheng')})
                }

            }else {
                layer.msg('请勿输入特殊符号');
            };
        })

    }


    layui.use(['form', 'layedit', 'laydate','table','element','laypage','flow'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate
            ,table=layui.table
            ,laypage=layui.laypage
            ,flow=layui.flow
            ,element=layui.element;

        laydate.render({
            elem: '#gonghuoshijian' //指定元素
            ,type: 'datetime'
        });

        $(document).on('click','.mater_btn',function () {
            $(this).parent().remove();
        })

        $('.close').click(function () {     //遮罩层隐藏
            $('.mask').hide();
            $('.masktow').hide();

        });
        jiazais();



        dayintishi('.dayin');

        //日期控件
        laydate.render({
            elem: '#date'
            ,type: 'datetime'
        });
        laydate.render({
            elem: '#date1'
            ,type: 'datetime'
        });
        var xiala;
        var jiauusid='';
        //执行渲染
        if(lbq('api/matperson/loadGysFeedSel.do')) {

            API.cailiaodiaozhuan({'type': 'a', 'p': getCookie('yanzheng')}, function () {
                console.log(arguments);
                xiala = arguments[0].contracts;
                console.log(xiala)
                //材料类型下拉加载
                $("[name='Mat_type']").html('')

                for(var i=0;i<xiala.length;i++){
                    $('[name="diaochu"]').append('<option value="'+xiala[i].cc_UUID+'">'+xiala[i].proName+'</option>-->')
                    $('[name="jieshou"]').append('<option value="'+xiala[i].cc_UUID+'">'+xiala[i].proName+'</option>-->')
                }

                form.render();//渲染下拉
                form.on('select(test)', function(data){
                    console.log(data.elem); //得到select原始DOM对象
                    console.log(data.value); //得到被选中的值
                    console.log(data.othis); //得到美化后的DOM对象
                    jiauusid=data.value;
                    ajaxs('/api/material/matSendManager.do','post',{'type':'b','remark':data.value,'p':getCookie('yanzheng')},function(data) {
                        console.log(data)
                        var d=data.data;
                        console.log(d,'adsadadaa')
                        $('.xuanzhong tbody').html('');
                        for(var i=0;i<d.length;i++){
                            if(!d[i].rm_Num){
                                d[i].rm_Num=0;
                            }
                            $('.xuanzhong tbody').append('  <tr id="'+d[i].id+'" names="'+d[i].mat_Name+'" guige="'+d[i].mat_Spec+'" nums="'+d[i].fin_Num+'" danwei="'+d[i].mat_Bit+'" rm_Code="'+d[i].rm_Code+'" qianshou="'+d[i].rm_Num+'">\n' +
                                '                            <td>\n' +
                                '                                <div class="layui-form-item" pane="">\n' +
                                    '                              <div class="layui-input-block">\n' +
                                        '                            <input type="checkbox" name="like1[write]" lay-filter="filter" lay-skin="primary" title=\'\'>\n' +
                                    '                            </div>\n' +
                                '                            </div>\n' +
                                '                            </td>\n' +
                                '                            <td>'+d[i].mat_Name+'</td>\n' +
                                '                            <td>'+d[i].mat_Spec+'</td>\n' +
                                '                            <td>'+d[i].rm_Num+'</td>'+
                                '                            <td>'+d[i].fin_Num+'</td>'+
                                '                            <td>'+d[i].mat_Bit+'</td>\n'+
                                '</tr>')
                        }
                        form.render();

                    })
                });
            })

        }
        //前后若干天可选，这里设置不能选过去的日期      最远可选1000天之后
        panduanshijiantow('#test-limit3','#test-limit4',1000,1000,'.chaxun');     //查询 开始结束时间判断

        //监听单个点击多选
        form.on('checkbox(filter)', function(data){
            console.log(data.elem); //得到checkbox原始DOM对象
            console.log(data.elem.checked); //是否被选中，true或者false
            console.log(data.value); //复选框value值，也可以通过data.elem.value得到
            console.log(data.othis); //得到美化后的DOM对象
            var _this=data.othis;
            var chuandi=new Object();

            chuandi.id=$(_this).parents('tr').attr('id');
            chuandi.names=_this.parents('tr').attr('names');
            chuandi.guige=_this.parents('tr').attr('guige');
            chuandi.num=_this.parents('tr').attr('nums');
            chuandi.qianshou=_this.parents('tr').attr('qianshou');
            chuandi.danwei=$(_this).parents('tr').attr('danwei');
            chuandi.rm_Code=$(_this).parents('tr').attr('rm_Code');
            console.log(chuandi)
            var as=true;
            var child = $(data.elem).parents('table').find('thead input[type="checkbox"]');         //找到tbody下的所有多选框
            console.log(child,'>>>>>>LLLLLLLLLLL')
            $('.tijiao').removeClass('layui-btn-disabled');
            $('tbody [name="like1[write]"]').each(function () {
                if(!$(this).is(':checked')){
                    as=false;
                    return false;
                }else{
                    as=true;
                };
            });
            if(as){
                child.each(function(index, item){                             //循环每个参数item  每个多选框
                    item.checked = data.elem.checked;                         //所有多选框  选中或取消选中
                });
            }else{
                child.each(function(index, item){                             //循环每个参数item  每个多选框
                    item.checked = false                         //所有多选框  选中或取消选中
                });
            }
            form.render();
//            console.log($(data.elem).parent(), 'is i======================== parent =')

            if(data.elem.checked){          //如果多选框被选中  给下半部添加内容
                $('.beixuan table tbody').append('<tr id="'+chuandi.id+'" nums="'+chuandi.num+'" rm_Code="'+chuandi.rm_Code+'">\n' +
                    '                                    <td class="names">'+chuandi.names+'</td>\n' +
                    '                                    <td class="guige">'+chuandi.guige+'</td>\n' +
                    '                                    <td class="nums1">'+chuandi.num+'</td>\n' +
                    '                                    <td class="qianshou">'+chuandi.qianshou+'</td>\n' +

                    '                                    <td class="nums">\n' +
                    '                                        <input type="number" class="inputs" lay-verify="required" value=""/>\n' +

                    '                                    </td>\n' +
                    '                                    <td class="guige">'+chuandi.danwei+'</td>\n' +

                    '                                </tr>')
            }else{                          //否则循环下半部所有的tr删除对应的tr
                $('.beixuan table tbody tr').each(function () {
                    if($(this).attr('id')==chuandi.id){
                        $(this).remove();
                    }

                })

            }
            $('.inputs').on('focus',function () {
                console.log($(this))
                var nums=$(this).parents('tr').attr('nums');
                nums=parseInt(nums);
                $(this).keyup(function () {
                    console.log($(this).val()<=0)
                    console.log($(this).val())

                    if($(this).val()<0||$(this).val()>nums){
                        $('.tijiao').hide();
                        layer.msg('数量不能为负或大于签收数量');
                        $(this).val('');
                        return;
                    }else{
                        $('.tijiao').show();
                    }
                })
            })

        });
        var uuids='';
        form.on('select(test3)', function(data){
            console.log(data.elem); //得到select原始DOM对象
            console.log(data.value); //得到被选中的值
            console.log(data.othis); //得到美化后的DOM对象
            uuids=data.value;
        });


        var uuids='';       //接受合同id;
        var dizhi='';       //接受合同地址;

        //监听工具条
        table.on('tool(test)', function(obj){ //注<span class="maohao">：</span>tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值
            var tr = obj.tr; //获得当前行 tr 的DOM对象

            if(layEvent === 'xiangqing'){ //详情
                //do somehing
                var d=obj.data;
                $('.xiangmus').html();
                $('.xuanzhong tbody').html('');
                $('.diaochu').html(d.proName1);
                $('.jieshou').html(d.proName2);
                $('.times').html(d.createTime);
                $('.operator').html(d.createUser);



                console.log(obj)
                ajaxs('/api/material/matSendManager.do','post',{'type':'c','remark':obj.data.mm_Code,'p':getCookie('yanzheng')},function(data) {
                    console.log(data);
                    var d=data.data;
                    if(d.length>0){
                        $('.xiangmus').html(d[0].eppName+'('+d[0].eppStaEnd+')');
                        $('.masktow').show();

                        for(var i=0;i<d.length;i++){
                            $('.xuanzhong tbody').append(' <tr>\n' +
                                '                                    <td>'+d[i].mat_Name+'</td>\n' +
                                '                                    <td>'+d[i].mat_Spec+'</td>\n' +
                                '                                    <td>'+d[i].mat_Bit+'</td>\n' +

                                '                                    <td>'+d[i].num+'</td>\n' +
                                '                                    <td>'+d[i].rm_Num+'</td>\n' +
                                '                                    <td>'+d[i].fin_Num+'</td>\n' +
                                '                                </tr>')

                        }
                    }else{
                        $('.masktow').hide();
                        layer.msg('未获取到详细数据');
                    }

                });


            }else if(layEvent==='look'){
                console.log(obj)
                sessionStorage.UUid=obj.data.feed_Code;
                location.href='./cailiaoApplyDetails.html';
            }
        });

        form.on('submit(_subm)',function (data) {
            console.log(data.field)
            var cailiao='';
            if( $('.beixuan tbody tr').length==0){
                layer.msg('请选择原料');
                return false;
            };
            $('.mask .beixuan tbody tr').each(function () {
                cailiao+=$(this).attr('id')+','+$(this).children('.nums').children('input').val()+'|';
            });
            cailiao=cailiao.substr(0,cailiao.length-1);
            console.log(cailiao)
            data.field.a_uuid=jiauusid;
            data.field.b_uuid  =uuids
            data.field.matStr  =cailiao;
            data.field.p=getCookie('yanzheng');
            console.log(data.field)
            Btnon('.tijiao');      //  禁止按钮点击
            formAlertAjax('/api/material/matSend.do',data.field,'.tijiao');
            return false;
        })
        $("[name='feed_Code']").blur(function () {
            console.log($(this).val()!= $("[name='namespan']").val())
            if($(this).val()== $("[name='namespan']").val()){
                return;
            }
            ajaxs('/api/public/cheName.do','get',{'type':3,'name':$(this).val()},function (data) {
                console.log(data)
                if(data.code==0){
                    if(data.data=='1'){
                        layer.msg('申请单号已存在 请重新输入');
                        $('.tijiao').attr('disabled','true').addClass('layui-btn-disabled');//禁止提交按钮点击
                    }else{
                        layer.msg('申请单号可用');

                        $('.tijiao').removeAttr('disabled').removeClass('layui-btn-disabled');//禁止提交按钮点击

                    }

                }
            })
        })
        inputs();
        //材料添加
        $('.material_C').click(function () {
            var _dom=$(this).parents('.materialone').html();
            $('.materialone').after('<div class="material">'+_dom+'</div>');

            form.render();
        })

        //判断数量输入框是否为空




    })




</script>
</body>
</html>